//
//  XZMyMessageCell.m
//  Teecloud
//
//  Created by PC on 2018/11/9.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "XZMyMessageCell.h"
#import "GMlevelView.h"
#import "GMPhotoCell.h"
#import "GMPlayerVoideCell.h"
#import "TZImagePickerController.h"
#import <KSPhotoBrowser/KSPhotoBrowser.h>
#import "GMLookPDFVC.h"
#import "XZMsgList.h"
#import "GMAttachListModel.h"
#import "GMVoiceListModel.h"
@interface XZMyMessageCell ()<UICollectionViewDataSource,UICollectionViewDelegate,TZImagePickerControllerDelegate,UICollectionViewDelegateFlowLayout,UITableViewDataSource,UITableViewDelegate>
/**************************MsgBoby****************************/
@property (weak, nonatomic) IBOutlet UIImageView *msgHeadUrl;//头像
@property (weak, nonatomic) IBOutlet UILabel *msgUserName;//名称
@property (weak, nonatomic) IBOutlet UILabel *msgSendTime;//发送时间
@property (weak, nonatomic) IBOutlet UILabel *msgTypeName;//消息类别
@property (weak, nonatomic) IBOutlet GMlevelView *msgLevelView;//等级
@property (weak, nonatomic) IBOutlet UILabel *msgContent;//内容
//语音view
@property (weak, nonatomic) IBOutlet UITableView *msgAvoidView;
//图片view
@property (weak, nonatomic) IBOutlet UICollectionView *msgImgView;
//附带信息
@property (weak, nonatomic) IBOutlet UIView *msgAttachmentView;
//附加信息view向右的约束
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *right;
@property (weak, nonatomic) IBOutlet UIImageView *msgAttachmentImg;
@property (weak, nonatomic) IBOutlet UIButton *msgAttachmentBtn;
@property (weak, nonatomic) IBOutlet UIButton *msgPositionBtn;

//操作按钮
@property (weak, nonatomic) IBOutlet UIButton *codeBtn;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgLevelWidth;

//MsgBoby的视图的总高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgHeight;
//MsgBoby的语音视图的高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgAvoidViewHeight;
//MsgBoby的图片视图的高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgImgViewHeight;
//MsgBoby的附加视图的高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgAttachmentViewHeight;


/************************* Quote 同上 *****************************/
@property (weak, nonatomic) IBOutlet UIImageView *quoteHeadUrl;
@property (weak, nonatomic) IBOutlet UILabel *quoteUserName;
@property (weak, nonatomic) IBOutlet GMlevelView *quoteLevelView;
@property (weak, nonatomic) IBOutlet UILabel *quoteSendTime;
@property (weak, nonatomic) IBOutlet UILabel *quoteMsgTypeName;
@property (weak, nonatomic) IBOutlet UILabel *quoteContent;
@property (weak, nonatomic) IBOutlet UITableView *quoteAvoidView;
@property (weak, nonatomic) IBOutlet UICollectionView *quoteImgView;
@property (weak, nonatomic) IBOutlet UIView *quoteAttachmentView;
//附加图片
@property (weak, nonatomic) IBOutlet UIImageView *quoteAttachementImg;
//附加名称
@property (weak, nonatomic) IBOutlet UIButton *quoteAttachementTitleBtn;
//播放的位置
@property (weak, nonatomic) IBOutlet UIButton *quotePosBtn;

//等级view的宽度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *quoteLevelWidth;

//Quote视图的高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *quoteViewHeight;
//Quote的图片视图的高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *quoteImgViewHeight;
//Quote的语音视图的高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *quoteAvoidViewHeight;
//Quote的附加视图的高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *quoteAttachmentViewHeight;

@end
#define BorderColor [UIColor colorWithHexString:@"#FF9900" andAlpha:1.0]
@implementation XZMyMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    /************Msg Quote 视图的相关view的属性设置**************/
    //消息类别的边框颜色 边框宽度 圆角
    self.msgTypeName.layer.borderColor = BorderColor.CGColor;
    self.msgTypeName.layer.borderWidth = 0.5f;
    
    self.quoteMsgTypeName.layer.borderWidth = 0.5f;
    self.quoteMsgTypeName.layer.borderColor = BorderColor.CGColor;

    
    //解释按钮
    self.codeBtn.layer.cornerRadius = 2.0f;
    self.codeBtn.clipsToBounds = true;
    
    //TableView的属性设置
    _msgAvoidView.delegate =self;
    _msgAvoidView.dataSource = self;
    _msgAvoidView.scrollEnabled = false;
    [_msgAvoidView registerNib:[UINib nibWithNibName:@"GMPlayerVoideCell" bundle:nil] forCellReuseIdentifier:@"GMPlayerVoideCell"];
    
    _quoteAvoidView.delegate = self;
    _quoteAvoidView.dataSource = self;
    _quoteAvoidView.scrollEnabled = false;
    [_quoteAvoidView registerNib:[UINib nibWithNibName:@"GMPlayerVoideCell" bundle:nil] forCellReuseIdentifier:@"GMPlayerVoideCell"];
    
    //Collectionview的属性设置
    _msgImgView.scrollEnabled = false;
    _msgImgView.backgroundColor = kWhiteColor;
    _msgImgView.dataSource = self;
    _msgImgView.delegate = self;
    [_msgImgView registerNib:[UINib nibWithNibName:@"GMPhotoCell" bundle:nil] forCellWithReuseIdentifier:@"GMPhotoCell"];
    
    _quoteImgView.scrollEnabled = false;
    _quoteImgView.backgroundColor = kEAEAEAColor;
    _quoteImgView.dataSource = self;
    _quoteImgView.delegate = self;
    [_quoteImgView registerNib:[UINib nibWithNibName:@"GMPhotoCell" bundle:nil] forCellWithReuseIdentifier:@"GMPhotoCell"];
    
}
- (void)setModel:(XZMsgList *)model{
    _model = model;
    /*********************MsgBoby*****************/
    [self.msgHeadUrl yy_setImageWithURL:[NSURL URLWithString:model.MsgBody.UserInfo.HeadUrl] placeholder:[UIImage imageNamed:@"headPortrait"]];
    self.msgUserName.text = model.MsgBody.UserInfo.UserName;
    self.msgSendTime.text = model.MsgBody.SendTime;
    self.msgTypeName.text = model.MsgBody.MsgTypeName;
    [self.msgLevelView setCrownCount:model.MsgBody.UserInfo.GradeIconCount.CrownCount SunCount:model.MsgBody.UserInfo.GradeIconCount.SunCount MoonCount:(NSInteger)model.MsgBody.UserInfo.GradeIconCount.MoonCount StarCount:model.MsgBody.UserInfo.GradeIconCount.StarCount];
    
    //Msg等级view的宽度
    NSInteger msgTotalNum = model.MsgBody.UserInfo.GradeIconCount.CrownCount + model.MsgBody.UserInfo.GradeIconCount.SunCount+model.MsgBody.UserInfo.GradeIconCount.MoonCount+model.MsgBody.UserInfo.GradeIconCount.StarCount;
    self.msgLevelWidth.constant = msgTotalNum *20;
    //评论
    self.msgContent.text = model.MsgBody.Content;
    CGFloat msgContentHight = [self.msgContent getLableSizeWithMaxWidth:(DEVICE_WIDTH-48)].height;
    //语音
    if (model.MsgBody.VoiceList.count == 0) {
        self.msgAvoidViewHeight.constant = 0;
        self.msgAvoidView.hidden = true;
    }else{
        self.msgAvoidViewHeight.constant = model.MsgBody.VoiceList.count *30;
        self.msgAvoidView.hidden = false;
        [self.msgAvoidView reloadData];
    }
    //图片
    if (model.MsgBody.ImgFileList.count == 0) {
        self.msgImgViewHeight.constant = 0;
        self.msgImgView.hidden = true;
    }else{
        self.msgImgViewHeight.constant = 60;
        self.msgImgView.hidden = false;
        [self.msgImgView reloadData];
    }
    
    if (model.MsgBody.Attachment != nil) {
        self.msgAttachmentView.hidden = false;
        self.msgAttachmentViewHeight.constant = 30;
    }else{
        self.msgAttachmentView.hidden = true;
        self.msgAttachmentViewHeight.constant = 0;
    }
    //附加信息
    [self.msgAttachmentImg yy_setImageWithURL:[NSURL URLWithString:model.MsgBody.Attachment.HeadUrl] placeholder:DefealtImg];
    [self.msgAttachmentBtn setTitle:[NSString stringWithFormat:@"%@",model.MsgBody.Attachment.ResName] forState:UIControlStateNormal];
    [self.msgPositionBtn setTitle:[NSString stringWithFormat:@"【%@】",model.MsgBody.Attachment.PositionStr] forState:UIControlStateNormal];
    NSInteger resType = [model.MsgBody.Attachment.ResType integerValue];
    self.msgAttachmentBtn.userInteractionEnabled = true;
    if (resType > 2) {
        self.msgAttachmentBtn.userInteractionEnabled = false;
        [self.msgAttachmentBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    }else{
        [self.msgAttachmentBtn setTitleColor:k1168E6Color forState:UIControlStateNormal];
    }
    //Attachment.ResType=1&&Attachment.PositionStr!=null时显示
    if ([model.MsgBody.Attachment.ResType integerValue] == 1 && model.MsgBody.Attachment.PositionStr != nil) {
        self.
        self.msgPositionBtn.hidden = false;
    }else{
        self.msgPositionBtn.hidden = true;;
    }
    //如果没有附件信息 但是有追加安按钮就+18的高度
    NSInteger signCode = [model.Action.Code integerValue];
    if (self.msgAttachmentViewHeight.constant == 0) {
        if (signCode == 0) {
            self.msgHeight.constant = 38+msgContentHight+self.msgAvoidViewHeight.constant+self.msgImgViewHeight.constant+self.msgAttachmentViewHeight.constant+6;
        }else{
            self.msgHeight.constant = 38+msgContentHight+self.msgAvoidViewHeight.constant+self.msgImgViewHeight.constant+18+6+8;
        }
    }else{
        self.msgHeight.constant = 38+msgContentHight+self.msgAvoidViewHeight.constant+self.msgImgViewHeight.constant+self.msgAttachmentViewHeight.constant+6;
    }
   
    
    
    //解释按钮的逻辑
    self.codeBtn.userInteractionEnabled = true;
    self.codeBtn.hidden =false;
    NSInteger code = [model.Action.Code integerValue];
    if (code == -1) {
        self.right.constant = 55.f;
        [self.codeBtn setTitleColor:[UIColor colorWithHexString:@"888888" andAlpha:1.0] forState:UIControlStateNormal];
        self.codeBtn.backgroundColor = kWhiteColor;
        [self.codeBtn setTitle:[NSString stringWithFormat:@"已%@",model.Action.Name] forState:UIControlStateNormal];
        self.codeBtn.userInteractionEnabled = false;
    }else if (code == 0){
        self.right.constant = 8.f;
        self.codeBtn.hidden =true;
    }else if (code > 0){
        self.right.constant = 55.f;
         [self.codeBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
        self.codeBtn.backgroundColor = [UIColor colorWithHexString:@"0065EA" andAlpha:1.0f];
       [self.codeBtn setTitle:model.Action.Name forState:UIControlStateNormal];
    }
    
    
    /*******************************Quote*******************/
    [self.quoteHeadUrl yy_setImageWithURL:[NSURL URLWithString:model.Quote.UserInfo.HeadUrl] placeholder:[UIImage imageNamed:@"headPortrait"]];
    self.quoteUserName.text = model.Quote.UserInfo.UserName;
    self.quoteSendTime.text = model.Quote.SendTime;
    self.quoteMsgTypeName.text = model.Quote.MsgTypeName;
    [self.quoteLevelView setCrownCount:model.Quote.UserInfo.GradeIconCount.CrownCount SunCount:model.Quote.UserInfo.GradeIconCount.SunCount MoonCount:(NSInteger)model.Quote.UserInfo.GradeIconCount.MoonCount StarCount:model.Quote.UserInfo.GradeIconCount.StarCount];
    
    [self.quoteAttachementImg yy_setImageWithURL:[NSURL URLWithString:model.Quote.Attachment.HeadUrl] placeholder:DefealtImg];
    [self.quoteAttachementTitleBtn setTitle:model.Quote.Attachment.ResName forState:UIControlStateNormal];
    [self.quotePosBtn setTitle:[NSString stringWithFormat:@"【%@】",model.Quote.Attachment.PositionStr] forState:UIControlStateNormal];
    //ResType>2：显示黑色文字，表示不可点击
    NSInteger quoteResType = [model.Quote.Attachment.ResType integerValue];
    self.quoteAttachementTitleBtn.userInteractionEnabled = true;
    if (quoteResType > 2) {
        self.quoteAttachementTitleBtn.userInteractionEnabled = false;
        [self.quoteAttachementTitleBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    }else{
        [self.quoteAttachementTitleBtn setTitleColor:k1168E6Color forState:UIControlStateNormal];
    }
    //Attachment.ResType=1&&Attachment.PositionStr!=null时显示
    if ([model.Quote.Attachment.ResType integerValue] == 1 && model.Quote.Attachment.PositionStr != nil) {
        self.
        self.quotePosBtn.hidden = false;
    }else{
        self.quotePosBtn.hidden = true;;
    }
    //Quote等级view的宽度
    NSInteger quoteTotalNum = model.Quote.UserInfo.GradeIconCount.CrownCount + model.Quote.UserInfo.GradeIconCount.SunCount+model.Quote.UserInfo.GradeIconCount.MoonCount+model.Quote.UserInfo.GradeIconCount.StarCount;
    self.quoteLevelWidth.constant = quoteTotalNum *20;
    //评论
    self.quoteContent.text = model.Quote.Content;
    CGFloat quoteContentHight = [self.quoteContent getLableSizeWithMaxWidth:(DEVICE_WIDTH-94)].height;
    
    //打开Quote的相应控件
    self.quoteHeadUrl.hidden = false;
    self.quoteMsgTypeName.hidden = false;
    self.quoteSendTime.hidden = false;
    self.quoteUserName.hidden = false;
    //语音
    if (model.Quote != nil) {
        if (model.Quote.VoiceList.count == 0) {
            self.quoteAvoidViewHeight.constant = 0;
            self.quoteAvoidView.hidden = true;
        }else{
            self.quoteAvoidViewHeight.constant = model.Quote.VoiceList.count *30;
            self.quoteAvoidView.hidden = false;
            [self.quoteAvoidView reloadData];
        }
        
        if (model.Quote.ImgFileList.count == 0) {
            self.quoteImgViewHeight.constant = 0;
            self.quoteImgView.hidden = true;
        }else{
            self.quoteImgViewHeight.constant = 60;
            self.quoteImgView.hidden = false;
            [self.quoteImgView reloadData];
        }
        
        if (model.Quote.Attachment != nil) {
             self.quoteAttachmentViewHeight.constant = 30;
            self.quoteAttachmentView.hidden = false;
           
        }else{
            self.quoteAttachmentViewHeight.constant = 0;
            self.quoteAttachmentView.hidden = true;
            
        }
        
    self.quoteViewHeight.constant = 38+quoteContentHight+self.quoteAvoidViewHeight.constant+self.quoteImgViewHeight.constant+self.quoteAttachmentViewHeight.constant+6;
    }else{
         //隐藏Quote的相应控件
        self.quoteHeadUrl.hidden = true;
        self.quoteMsgTypeName.hidden = true;
        self.quoteSendTime.hidden = true;
        self.quoteUserName.hidden = true;
        
        self.quoteAvoidViewHeight.constant = 0;
        self.quoteAvoidView.hidden = true;
        
        self.quoteImgViewHeight.constant = 0;
        self.quoteImgView.hidden = true;
        
        self.quoteAttachmentViewHeight.constant=0;
        self.quoteAttachmentView.hidden = true;
        
        
        self.quoteViewHeight.constant = 0;
    }
    
    //cell总高度
    if (self.quoteViewHeight.constant == 0) {
        model.cellHeight = self.msgHeight.constant + self.quoteViewHeight.constant+1;
    }else{
        model.cellHeight = self.msgHeight.constant + self.quoteViewHeight.constant+10;
    }
    
}

#pragma mark - CollectViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if ([collectionView isEqual:self.msgImgView]) {
        return self.model.MsgBody.ImgFileList.count;
    }
    return self.model.Quote.ImgFileList.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    GMPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GMPhotoCell" forIndexPath:indexPath];
    GMAttachListModel *model= [[GMAttachListModel alloc]init];
    if ([collectionView isEqual:self.msgImgView]) {
        model= self.model.MsgBody.ImgFileList[indexPath.row];
    }else{
        model= self.model.Quote.ImgFileList[indexPath.row];
    }
    
    if ([model.FileType isEqualToNumber:@(3)]) {
        [cell.photoImg yy_setImageWithURL:[NSURL URLWithString:model.Url] placeholder:DefealtImg];
    }else if ([model.FileType isEqualToNumber:@(4)]){
        cell.photoImg.image =[UIImage imageNamed:@"doc-pdf"];
    }else if ([model.FileType isEqualToNumber:@(5)]){
        cell.photoImg.image =[UIImage imageNamed:@"doc-ppt"];
    }else if ([model.FileType isEqualToNumber:@(6)]){
        cell.photoImg.image =[UIImage imageNamed:@"doc-word"];
    }else if ([model.FileType isEqualToNumber:@(7)]){
        cell.photoImg.image =[UIImage imageNamed:@"doc-excel"];
    }else if ([model.FileType isEqualToNumber:@(8)]){
        cell.photoImg.image =[UIImage imageNamed:@"doc-rar"];
    }else if ([model.FileType isEqualToNumber:@(9)]){
        cell.photoImg.image =[UIImage imageNamed:@"doc-zip"];
    }else{
        cell.photoImg.image =[UIImage imageNamed:@"doc-other"];
    }
    cell.delectBtn.hidden=YES;
    return cell;
}
//设置每个item的尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((DEVICE_WIDTH-88-10-10-40)/5, (DEVICE_WIDTH-88-10-10-40)/5);
}

//设置每个item的UIEdgeInsets
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 0,10,4);
}

//设置每个item水平间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 4;
}
//设置每个item垂直间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 4;
}
//点击item方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    /**放大图片*/
    if ([collectionView isEqual:self.msgImgView]) {
        /**放大图片*/
        GMAttachListModel *fileModel= self.model.MsgBody.ImgFileList[indexPath.row];
        if ([fileModel.FileType isEqualToNumber:@(3)]) {
            GMPhotoCell * cell = (GMPhotoCell *)[self collectionView:collectionView cellForItemAtIndexPath:indexPath];//即为要得到的cell
            NSMutableArray *items = @[].mutableCopy;
            NSInteger count = self.model.MsgBody.ImgFileList.count;
            for (int i = 0; i < count; i++) {
                GMAttachListModel *model= self.model.MsgBody.ImgFileList[i];
                if ([model.FileType isEqualToNumber:@(3)]) {
                    UIImageView *imgV = cell.photoImg;
                    KSPhotoItem *item = [KSPhotoItem itemWithSourceView:imgV imageUrl:[NSURL URLWithString:model.Url]];
                    [items addObject:item];
                }
            }
            KSPhotoBrowser *browser = [KSPhotoBrowser browserWithPhotoItems:items selectedIndex:indexPath.row];
            browser.dismissalStyle = KSPhotoBrowserInteractiveDismissalStyleRotation;
            browser.backgroundStyle = KSPhotoBrowserBackgroundStyleBlurPhoto;
            browser.loadingStyle = KSPhotoBrowserImageLoadingStyleDeterminate;
            browser.pageindicatorStyle = KSPhotoBrowserPageIndicatorStyleDot;
            browser.bounces = NO;
            [browser showFromViewController:self.parentController];
        }else{
            GMLookPDFVC *preview = [[GMLookPDFVC alloc] init];
            preview.model = fileModel;
            [self.parentController.navigationController pushViewController:preview animated:YES];
        }
    }else{
        /**放大图片*/
        GMAttachListModel *fileModel=
        self.model.Quote.ImgFileList[indexPath.row];
        if ([fileModel.FileType isEqualToNumber:@(3)]) {
            GMPhotoCell * cell = (GMPhotoCell *)[self collectionView:collectionView cellForItemAtIndexPath:indexPath];//即为要得到的cell
            NSMutableArray *items = @[].mutableCopy;
            NSInteger count = self.model.Quote.ImgFileList.count;
            for (int i = 0; i < count; i++) {
                GMAttachListModel *model= self.model.Quote.ImgFileList[i];
                if ([model.FileType isEqualToNumber:@(3)]) {
                    UIImageView *imgV = cell.photoImg;
                    KSPhotoItem *item = [KSPhotoItem itemWithSourceView:imgV imageUrl:[NSURL URLWithString:model.Url]];
                    [items addObject:item];
                }
            }
            KSPhotoBrowser *browser = [KSPhotoBrowser browserWithPhotoItems:items selectedIndex:indexPath.row];
            browser.dismissalStyle = KSPhotoBrowserInteractiveDismissalStyleRotation;
            browser.backgroundStyle = KSPhotoBrowserBackgroundStyleBlurPhoto;
            browser.loadingStyle = KSPhotoBrowserImageLoadingStyleDeterminate;
            browser.pageindicatorStyle = KSPhotoBrowserPageIndicatorStyleDot;
            browser.bounces = NO;
            [browser showFromViewController:self.parentController];
        }else{
            GMLookPDFVC *preview = [[GMLookPDFVC alloc] init];
            preview.model = fileModel;
            [self.parentController.navigationController pushViewController:preview animated:YES];
        }
    }
}

#pragma mark - TableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if ([tableView isEqual:self.msgAvoidView]) {
        return  self.model.MsgBody.VoiceList.count;
    }
    return self.model.Quote.VoiceList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    kWeakObject(self)
    NSString *voiceStr = nil;//msg quote 的语音标识
    GMPlayerVoideCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GMPlayerVoideCell" forIndexPath:indexPath];
    GMVoiceListModel *model = [[GMVoiceListModel alloc]init];
    if ([tableView isEqual:self.msgAvoidView]) {
        voiceStr = @"MSG";
         cell.contentView.backgroundColor = kWhiteColor;
        model = self.model.MsgBody.VoiceList[indexPath.row];
    }else{
        voiceStr = @"QUOTE";
        cell.contentView.backgroundColor = kEAEAEAColor;
         model = self.model.Quote.VoiceList[indexPath.row];
    }
    
    //语音读与未读
    cell.readBlock = ^{
        weakself.hasReadBlock(indexPath.row, model.Id,voiceStr);
    };
    cell.model = model;
    return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 30;
}



/**
 Action-Code按钮操作

 @param sender Action-Code
 */
- (IBAction)codeButtonAction:(UIButton *)sender {
    if (self.ActionBlock) {
        self.ActionBlock(self.model);
    }
}

/**
 MsgBody或者Quote跳转到指定的播放时间
 Msg.tag = 102  Quote.tag = 103
 @param sender 按钮
 */
- (IBAction)positionLoactionAction:(UIButton *)sender {
    NSInteger tag = sender.tag;
    if (self.PostionLoactionBlock) {
        self.PostionLoactionBlock(tag, self.model);
    }
}


/**
 点击图片旁边的文字ResName
 Msg.tag = 100  Quote.tag = 101
 @param sender 按钮
 */
- (IBAction)resNameBtnAction:(UIButton *)sender {
    NSInteger tag = sender.tag;
    if (self.ResNameBlock) {
        self.ResNameBlock(tag, self.model);
    }
}

@end
